from game.model import LLM
from game.background import story_background, first_choices
from game.game_node import GameNode



def get_user_input()->int:
    def post_process(user_input: str) -> int:
        if user_input in ['1', '2', '3']:
            return int(user_input)
        return None
        
    while True:
        user_choice = input('你的选择是:')
        result = post_process(user_choice)
        if result is not None:
            return result
        print('输入无效,请输入1、2或3')
    
def main():    
    story_llm = LLM()
    # game start
    cur_node = GameNode(description=story_background,
                        choices=first_choices)
    cur_node.show_info()

    while True:
        user_choice = get_user_input()
        cur_node = cur_node.generate_next_node(story_llm, user_choice)
        cur_node.show_info()
        if cur_node.isEnd():
            break
        

if __name__ == '__main__':
    main()

    
    
